#include "shuffle.h"

#include "fragment.h"

static void
shuffle_fragment (FILE_FRAGMENT * fragment, gboolean has_to_shuffle, guint number_of_bits_to_shuffle)
{
	guint iterator = 0;
	guint position = 0;

	if (has_to_shuffle)
	{
		for (iterator = 0; iterator < number_of_bits_to_shuffle; iterator++)
		{	
			position =  rand() % 10;
			fragment->data[position] = 'A';
		}
	}

	return;
}

static void
shuffle_fragment_group (FILE_FRAGMENT_GROUP * fragment_group, gboolean has_to_shuffle, guint number_of_bits_to_shuffle)
{
	FILE_FRAGMENT * fragment            = NULL;
	guint           number_of_fragments = 0;
	guint           iterator            = 0;

	number_of_fragments = g_list_length (fragment_group->data_list);

	for (iterator = 0; iterator < number_of_fragments; iterator++)
	{
		fragment = (FILE_FRAGMENT *) g_list_nth_data (fragment_group->data_list, iterator);
		shuffle_fragment (fragment, has_to_shuffle, number_of_bits_to_shuffle);
		//fragment_group->data_list = g_list_insert (fragment_group->data_list, fragment, iterator);
	}

	return;
}

void 
shuffle (GList * blocks)
{
	FILE_FRAGMENT_GROUP * fragment_group            = NULL;
	guint                 number_of_fragment_groups = 0;
	guint                 iterator                  = 0;
	gboolean              has_to_shuffle            = TRUE;
	guint                 number_of_bits_to_shuffle = 4; 

	number_of_fragment_groups = g_list_length (blocks);

	for (iterator = 0; iterator < number_of_fragment_groups; iterator++)
	{
		fragment_group = (FILE_FRAGMENT_GROUP *) g_list_nth_data (blocks, iterator);
		shuffle_fragment_group (fragment_group, has_to_shuffle, number_of_bits_to_shuffle);
		//blocks = g_list_insert (blocks, fragment_group, iterator);
	}

	return;
}
